<script setup name="Student">
    import {reactive, ref} from "vue";
    //import axios from "axios";
    import {studentApi} from "@/api/student.js";

    let studentList = ref([])
    //搜索条件
    let searchCondition = reactive({
        name: '',
        gender: ''
    })

    /*axios.get('http://localhost:8080/student/list').then(response => {
        console.log(response.data)
		let result = response.data;
        if (result.code == 0) {
            studentList.value = result.data
		}
	}).catch(error => {

	})*/

    search()

    function search() {
        /*axios.get('http://localhost:8080/student/list', {params: searchCondition}).then(response => {
            console.log(response.data)
            let result = response.data;
            if (result.code == 0) {
                studentList.value = result.data;
            }
        })*/
        studentApi.list(searchCondition).then(result => {
            if (result.code == 0) {
                studentList.value = result.data
            }
        })
    }
</script>

<template>
    <div class="back">
        姓名：<input type="text" v-model="searchCondition.name">
        性别：<input type="text" v-model="searchCondition.gender">
        <button @click="search">搜索</button>
        <el-table :data="studentList" style="width: 100%">
            <el-table-column fixed prop="id" label="ID" width="150" />
            <el-table-column prop="name" label="姓名"/>
            <el-table-column prop="age" label="年龄"/>
            <el-table-column prop="gender" label="性别"/>
            <el-table-column fixed="right" label="Operations" min-width="120">
                <template #default>
                    <el-button link type="primary" size="small" @click="handleClick">
                        Detail
                    </el-button>
                    <el-button link type="primary" size="small">Edit</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<style scoped>
    .back {
        background-color: skyblue;
        box-shadow: 0 0 10px;
        border-radius: 10px;
        padding: 20px;
    }

    button {
        margin: 0 5px;
    }

    li {
        font-size: 20px;
    }
</style>